/**
 * 
 */
package org.gas.barapraja.util;

import org.gas.barapraja.db.entity.Account;


/**
 * Parsing utility class
 * @author gilang
 *
 */
public class ParserUtility implements ParserFactory{
	
	/**
	 * the parser to be used
	 */
	private AccountParser accountParser;
	
	/**
	 * Default user's xml class location
	 */
	
	public static String DEFAULT_USERS_FILE=System.getProperty("user.dir")+"/"+"users.xml";
	
	/**
	 * reference to this class
	 */
	private static ParserFactory factory;
	
	/**
	 * default constructor
	 */
	ParserUtility() {
		accountParser=new AccountParser();
	}
	
	/**
	 * Self refence to <code>ParserUtility</code> class
	 * @return this class
	 */
	public static ParserFactory getFactory(){
		if(factory==null)
			factory=new ParserUtility();
		return factory;
	}


	/* (non-Javadoc)
	 * @see org.gas.barapraja.util.ParserFactory#parseAccount(java.lang.String)
	 */
	@Override
	public Account parseAccount(String key) {
		accountParser.parseFile(DEFAULT_USERS_FILE);
		return accountParser.getObject(key);
	}

	@Override
	public Account parseAccountNumber(String number) {
		accountParser.parseFile(DEFAULT_USERS_FILE);
		return accountParser.getAccountByAddress(number);
	}
	
	

}
